var time = {
 // setDate 带新增删除的时间格式化
 // time(必传) : 时间戳，key：展示方式， 
 // staus: add新增几日，del减去几日与num绑定，num：增加或减去日子具体数
 // hasTime: 是否含有时分秒
 setDate(stamp, staus, num, key = "-", hasTime = false) {
    let oneDayTime = 24 * 60 * 60 * 1000; // 一周的时间
    // 将time时间戳 先格式化一下
    if (key === '年月日') key = ["年", "月", "日"];
    else key = [key, key, ""]
    if (staus === "add") stamp += (num * oneDayTime);
    if (staus === "del") stamp -= (num * oneDayTime);
    let date = new Date(stamp);
    let YY = date.getFullYear()
    let MM = date.getMonth() + 1
    if(MM<10) MM = "0"+MM;
    let DD = date.getDate();
    if(DD<10) DD = "0"+DD;
    let hh = date.getHours();
    if(hh<10) hh = "0"+hh;
    let mm = date.getMinutes();
    if(mm<10) mm = "0"+mm;
    let ss = date.getSeconds();
    if(ss<10) ss = "0"+mm;
    let str = YY + key[0] + MM + key[1] + DD + key[2]
    if(hasTime) str+=" "+hh+":"+mm+":"+ss;
    return str
  },
  formatHour: function (value) {
    var hour = Math.floor(value / 60);
    return hour;
  },
  formatMin: function (value) {
    var min = (value % 60);
    return min;
  },
  // 转时间戳
  getTimes: function (val) {
    let date = new Date(val)
    let times = date.getTime()
    return times
  },
  timedifference: function (val) {
    var value = '' + val;
    value = value.replace(getRegExp('-', 'g'), '/')
    console.log('天', value)
    var stime = Date.parse(getDate(value)); //获得开始时间的毫秒数
    var etime = Date.parse(getDate()); //获得结束时间的毫秒数
    var usedTime = etime - stime; //两个时间戳相差的毫秒数
    var days = Math.floor(usedTime / (24 * 3600 * 1000)) + '';
    //计算出小时数
    var leave1 = usedTime % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
    var hours = Math.floor(leave1 / (3600 * 1000)); //将剩余的毫秒数转化成小时数
    //计算相差分钟数
    var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数
    var minutes = Math.floor(leave2 / (60 * 1000)); //将剩余的毫秒数转化成分钟
    //计算相差秒数
    var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
    var seconds = Math.floor(leave3 / 1000); //将剩余的毫秒数转化成秒数

    // var dayStr = days == 0 ? "" : days + "d:";
    var hoursStr = hours == 0 ? "" : hours + "h:";
    var minutesStr = minutes == 0 ? "" : minutes + "m:"
    var time = days.slice(1);
    return time;
  }, //计算两个时间之间的时间差
  timediffHour: function (val) {
    var value = '' + val;
    value = value.replace(getRegExp('-', 'g'), '/')
    console.log('小时', value)
    var stime = Date.parse(getDate(value)); //获得开始时间的毫秒数
    var etime = Date.parse(getDate()); //获得结束时间的毫秒数
    var usedTime = etime - stime; //两个时间戳相差的毫秒数
    var days = Math.floor(usedTime / (24 * 3600 * 1000)) + '';
    //计算出小时数
    var leave1 = usedTime % (24 * 3600 * 1000); //计算天数后剩余的毫秒数
    var hours = Math.floor(leave1 / (3600 * 1000)); //将剩余的毫秒数转化成小时数


    var time = Math.abs(hours);
    return time;
  },
  // 转时间戳
  getTimess: function (val) {
    var value = val.split(' ')
    var times = value[0]
    // console.log(times)
    return times
  },
  // 修改时间（不要秒）
  getset: function (val) {
    var value = val.split(' ')
    var times = value[0]
    var timez = value[1].split(':')
    // console.log(times)
    var array = times + ' ' + timez[0] + ":" + timez[1]
    return array
  },
  // 只要时间分钟和小时
  getset1: function (val) {
    var value = val.split(' ')
    var times = value[0]
    var timez = value[1].split(':')
    // console.log(times)
    var array = timez[0] + ":" + timez[1]
    return array
  },
  // 只要时间分钟和小时
  getset2: function (val) {
    // var value=val.split(' ')
    // var times = value[0]
    var timez = val.split(':')
    // console.log(times)
    var array = timez[0] + ":" + timez[1]
    return array
  },
  // 只要时间分钟和小时
  getset3: function (val) {
    var value = val.split(' ')
    var times = value[0]

    var timez = times.split('-')
    console.log(times)
    var array = timez[0] + "/" + timez[1] + "/" + timez[2]
    return array
  },
    // 只要时间分钟和小时
    getset4: function (val,type,types) {
      var value = val.split('-')
      if(type ==types){
        return value[1]+'/'+value[2]
      }else{
        return value[2]
      }

    },
  // 修改大小写
  famtimess: function (val) {
    console.log(times)
    return times
  },
  toDate: function (number, type) {
    console.log(number)
    // var arr = number.split('-')
    arr2 = arr[2].split(' ')
    var date = Date.parse(getDate(number));

    // var Y = date.getFullYear();
    // var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    // var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    // var h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
    // var m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
    // var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();+ arr2[0];
  },
  
  getseyear: function (num) {
    // console.log(num)
    var arr = num.split('-')
    var time = arr[0] + '.' + arr[1]
    return time
  },
  getseyears: function (num) {
    // console.log(num)
    if(num == null || num == undefined  || num== ''){
      return ''
    }else{
      var arr = num.split(' ')
      var time = arr[0].split('-')
      var times = time[1] + '月' + time[2] + '日'
      return times

    }
  },
  getseyear2: function (num) {
    console.log(num)
    var arr = num.split(' ')
    var time = arr[0].split('-')
    var times = time[1] + '-' + time[2]
    return times
  },
  getseyears3: function (num) {
    // console.log(num)
    if(num == null || num == undefined  || num== ''){
      return ''
    }else{
      var arr = num.split(' ')
      var time = arr[1].split(':')
      var times = time[0] + ':' + time[1]
      return times

    }
  },
  getseyears4: function (num) {
    // console.log(num)
    if(num == null || num == undefined  || num== ''){
      return ''
    }else{
      var arr = num.split(' ')
      var arr1 = arr[1].split(':')
      var time = arr[0].split('-')
      var times = time[1] + '月' + time[2] + '日'+' '+arr1[0] + ':'+ arr1[1]
      return times

    }
  },
  dislodgeZero: function (str) {
    console.log(str)
    var strArray = str.split('-');
    strArray = strArray.map(function (val) {
      if (val[0] == '0') {
        return val = val.slice(1);
      } else {
        return val;
      }
    })
    arr = strArray.join('-');
    var abc = arr.split('-');

    console.log(abc[2])

    return abc[2]
  },
  gettimeis: function (str) {
    var strArray = str.split(' ');

    var ysers = strArray[0]
    var dates = strArray[1]
    // console.log(ysers)
    var yser = ysers.split('-');
    var date = dates.split(':');
    var strs = yser[1] + '-' + yser[2] + " " + date[0] + ":" + date[1]

    return strs
  },
  distance: function (str) {
    // console.log(str)
    var atr = Math.round(str / 1000)
    // console.log(atr)
    return atr
  },
  // 时间去0
  dislodgeZeros: function (str) {
    var strArray = str.split(':');
    strArray = strArray.map(function(val) {
        if (val[0] == '0') {
            return val = val.slice(1);
        }else{
            return val;
        }
    })
    if(strArray[0]<=0){
      return strArray[1] + '分钟'

    }else{
      
    return strArray[0] + '小时'  +strArray[1] + '分钟'
    }
    // console.log(strArray)
  },
  // 火车票价格
  price:function(item,type){
    var price
    var ying = []
    // var ruan = []
    // if(item.yz_num == '--'){
      // 2
      if(item.edz_price != 0){
        ying.push(item.edz_price)
      }
      // 1
      if(item.ydz_price != 0){
        ying.push(item.ydz_price)
      }
      // 商
      if(item.swz_price != 0){
        ying.push(item.swz_price)
      }
      // 特
      if(item.tdz_price != 0){
        ying.push(item.tdz_price)
      }
      // 硬座
      if(item.yz_price != 0){
        ying.push(item.yz_price)
      }
      // 硬卧
      if(item.yw_price != 0){
        ying.push(item.yw_price)
      }
      // 无座
      if(item.wz_price != 0){
        ying.push(item.wz_price)
      }
      // 软铺
      if(item.gjrw_price != 0){
        ying.push(item.gjrw_price)
      }
      // 高软铺
      if(item.rw_price != 0){
        ying.push(item.rw_price)
      }
      // 软座
      if(item.rz_price != 0){
        ying.push(item.rz_price)
      }
      // 动卧
      if(item.dwx_price != 0){
        ying.push(item.dwx_price)
      }
      ying.sort(function(a,b){
        return a > b ? 1 : -1
      })
      price = ying[0]
      if(price == undefined ||price == null){
        price =0
      }
      // console.log(ying)
      // price = Math.min.apply(null, ying)
      // console.log(item.edz_price)
      // price =  item.yz_price
    // }
    console.log(price)
    // console.log(item.yz_num)
    // console.log(item.edz_num)
    return price
  },
  timetype:function(row,item,items,cur){

  },
  substring:function(tel){
    var tels =tel.replace(tel.substring(3,7), "****")
    return tels
  },
  Substringed:function(identity){
    var ident =identity.replace(identity.substring(6,15), "*********")
    return ident
  }
}
module.exports = {
  formatHour: time.formatHour,
  formatMin: time.formatMin,
  timedifference: time.timedifference,
  toDate: time.toDate,
  getTimes: time.getTimes,
  getTimess: time.getTimess,
  famtimess: time.famtimess,
  getset: time.getset,
  getset1: time.getset1,
  getseyear2: time.getseyear2,
  getseyears3:time.getseyears3,
  timediffHour: time.timediffHour,
  getseyear: time.getseyear,
  getseyears: time.getseyears,
  getset2: time.getset2,
  getset3: time.getset3,
  getset4: time.getset4,
  dislodgeZero: time.dislodgeZero,
  dislodgeZeros: time.dislodgeZeros,
  gettimeis: time.gettimeis,
  distance: time.distance,
  price: time.price,
  timetype: time.timetype,
  substring:time.substring,
  Substringed:time.Substringed,
  getseyears4:time.getseyears4,
  setDate:time.setDate
}